import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

/// 个人主页
class WormPersonalPage extends StatefulWidget {
  // 作者名称
  final String name;
  // 作者主页
  final String url;

  /// 构造方法
  WormPersonalPage(this.name, this.url, {Key key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => WormPersonalPageState();
}

/// 个人状态页
class WormPersonalPageState extends State<WormPersonalPage> {
  final webView = FlutterWebviewPlugin();

  @override
  void initState() {
    super.initState();

    // Url 改变监听
    webView.onUrlChanged.listen((String url) {
      print('Url改变：$url');
    });
    // 滑动监听
    webView.onScrollXChanged.listen((double offsetX) {
      print('x: $offsetX');
    });
    webView.onScrollYChanged.listen((double offsetY) {
      print('y: $offsetY');
    });
    webView.onStateChanged.listen((WebViewStateChanged state) {
      print('state: ${state.type}');
    });
  }

  @override
  Widget build(BuildContext context) {
    // 隐藏状态栏
    SystemChrome.setEnabledSystemUIOverlays([]);

    return WebviewScaffold(
      url: widget.url,
      withZoom: true,
      withLocalStorage: true,
      hidden: true,
      initialChild: Container(
        color: Colors.blueGrey,
        child: Center(
          child: Text('数据加载中...'),
        ),
      ),
    );
  }
}
